x86/MCE: Fix race condition in mctelem_reserve
authorFrediano Ziglio <frediano.ziglio@citrix.com>
Mon, 24 Feb 2014 11:07:41 +0000 (12:07 +0100)
committerJan Beulich <jbeulich@suse.com>
Mon, 24 Feb 2014 11:07:41 +0000 (12:07 +0100)
commit60ea3a3ac3d2bcd8e85b250fdbfc46b3b9dc7085
tree871814d2707ee3d6876d27287638ad71524a864a
parent869f5b6deab53bc924798df4dacfae92ee198cb4
x86/MCE: Fix race condition in mctelem_reserve

These lines (in mctelem_reserve)

        newhead = oldhead->mcte_next;
        if (cmpxchgptr(freelp, oldhead, newhead) == oldhead) {

are racy. After you read the newhead pointer it can happen that another
flow (thread or recursive invocation) change all the list but set head
with same value. So oldhead is the same as *freelp but you are setting
a new head that could point to whatever element (even already used).

This patch use instead a bit array and atomic bit operations.

Signed-off-by: Frediano Ziglio <frediano.ziglio@citrix.com>
Reviewed-by: Liu Jinsong <jinsong.liu@intel.com>
xen/arch/x86/cpu/mcheck/mctelem.c